<?php
//$proId=$_REQUEST['products'];
require_once 'includes/class.phpmailer.php';
session_start();
$sessid=session_id();

 //echo $pthumb;

?>


<style type="text/css">
	span#add-wishlist { color:#0000CC; padding:5px; font-size:12px; }	
</style>
<script language="javascript1.2">
function updateQty(id)
{
	var qtxt='qty'+id;
	var qtext = parseInt($('#qty'+id).val());
	
	//var test='qty'+id;
 //var f=document.getElementById(test).value();
 //alert("hi");
if(qtext=="" || isNaN(qtext) )
{
    alert("Please enter valid Quantity");
    return false;
}
else
{
var url = "<?php echo $base_url;?>ajax_updqty.php";
      $.post(url,
      { 'qty':qtext,'id':id},
      function(data)
      {
	//alert(data);
	if(data=='Record updates successfully')
	{
	  $('#update_error').html(data);
	  $("#update_error").fadeOut(2000);
	}
	else if(data=='')
	  window.location='index.php';
	else
	  window.location='index.php?'+data;
	      
      },
      'html'
      );
}
}

function set_online(objvalue,objTempID)
{
location.href="addtolocal.php?val="+objvalue +"&id="+objTempID;
}

</script>

<table width="100%">
<tr>
<td>
<div style="width: 950px; float: left; vertical-align: top;">
	<p style="text-align:center;"><img src="images/viewcart.png" /></p>
	
	<div class="fulldiv">
		<p class="pro_ptag">&nbsp;&nbsp;Your cat for Antiorn45 (<a href="#" class="bluelink">If it's not you click here</a>)</p>
	</div>

	<div class="fullbox_out">		
		<div class="fulldiv">
			<div class="fullbox_top"></div>
			<div class="fullbox_repeat">			
				
				<div class="sellpro_table">
					<div class="sellpro_row1">
						<strong class="orangehead">Qty</strong>
					</div>
					<div class="sellpro_row2">
						<strong class="orangehead">Product Description</strong>
					</div>
					<div class="sellpro_row2">
						<strong class="orangehead">Delivery Options</strong>
					</div>
					<div class="sellpro_row3">
						<strong class="orangehead">Price</strong>							
					</div>
				</div>
				
				<div class="sellpro_table">
					<div class="sellpro_row1">
						<p class="pro_ptag"><input type="text" class="inputbg" style="width:15px;" /> of 10</p>
						<p class="pro_ptag"><a href="#" class="bluelink">update</a></p>
						<p class="pro_ptag"><a href="#" class="bluelink">remove</a></p>
					</div>
					
					<div class="sellpro_row2">	
							<p class="sellpro_head pro_ptag" style="margin:5px 0px 5px 0px;">
							<a href='#' class="sellpro_head" title='$'>LG Blue Ray Player </a>
							</p>
							<p class="pro_ptag"><i>product owner - Binerzo78</i></p>
							<p class="pro_ptag"><i>local pick up - <font style="color:#000000;">available</font></i></p>					
					</div>
					
					<div class="sellpro_row2">
						<p class="pro_ptag"><input type="radio" name="" id="" />&nbsp;&nbsp;<label>Shipping</label></p>
						<p class="pro_ptag"><input type="radio" name="" id="" />&nbsp;&nbsp;<label>Local Pick up</label></p>
					</div>
					
					<div class="sellpro_row3">
						<p class="redtxt pro_ptag">$189</p>							
					</div>
				</div>
				
				<div class="sellpro_table">
					<p class="pro_ptag">
						<input class="yellow_btn" type="submit" value="save for later" />
					</p>
				</div>
							
			</div>
			<div class="fullbox_bot"></div>
			
			<div class="sellpro_table">
				<div class="sellpro_row4">
					<img src="images/shipping.png" />
				</div>	
				<div class="sellpro_row4">
					<div class="sellpro_row4_in">
						<div class="sellpro_row4_left">
							Product price:
						</div>
						<div class="sellpro_row4_right">
							$189.95
						</div>
					</div>
					
					<div class="sellpro_row4_in">
						<div class="sellpro_row4_left">
							Shipping:
						</div>
						<div class="sellpro_row4_right">
							$10.00
						</div>
					</div>
					
					<div class="sellpro_row4_in">
						<div class="sellpro_row4_left">
							Sales tax CA:
						</div>
						<div class="sellpro_row4_right">
							$2.00
						</div>
					</div>
					
					<div class="sellpro_row4_in">
						<div class="sellpro_row4_left">
							Sub-total:
						</div>
						<div class="sellpro_row4_right">
							<font class="redtxt">$189.95</font>
						</div>
					</div>
					
					<div class="sellpro_row4_in" style="border-top:1px solid #767676;">
						<div class="fulldiv pro_ptag">
							<div class="sellpro_row4_left">
								<a href="#" class="bluelink">Continue Shopping</a>
							</div>
							<div class="sellpro_row4_right">
								<input type="submit" value="Checkout" class="yellow_btn" style="float:right;">
							</div>
						</div>
					</div>
				</div>			
			</div>
			
		</div>
	
	</div>

	<div class="mypg_left_out">
		<div class="fulldiv">
			<div class="shourtbox" style="margin:5px 0px 5px 0px">
			Get it faster by choosing pick-up<br /><br />
			Safe and secure checkouts
			through Amazon Payments
			</div>
		</div>
		<div class="fulldiv">
			<div class="cartico_94"></div>
		</div>
	</div>
	
</div>
</td>
</tr>
</table>

<table width="100%" border="0">
<?php if($_SESSION['dmsg'])
{?>
  <tr>
    <td align="center" class="contentHeader"><strong><?php echo $_SESSION['dmsg'];$_SESSION['dmsg']="";?></strong></td>
  </tr>
  <?php }?>
  <?php if($_SESSION['cart_msg'])
{?>
  <tr>
    <td align="center" class="contentHeader"><strong><?php echo $_SESSION['cart_msg'];$_SESSION['cart_msg']="";?></strong></td>
  </tr>
  <?php }?>
  <tr>
    <td class="contentHeader"><h2>Shopping Cart </h2></td>
  </tr>
  <tr>
    <td><div id="update_error" style="color:red"></div></td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="5">
        <tr>
          <td colspan="2"><strong>Shipping Cart Items - Buy Now </strong></td>
          <td width="8%" nowrap="nowrap"><strong>Shipping</strong></td>
          <td width="30%"><strong>Local Pickup </strong></td>
          <td width="9%"><strong>Taxes</strong></td>
          <td width="8%"><strong>Price</strong></td>
          <td width="6%" colspan="2"><strong>Qty</strong></td>
        </tr>
        <?php
		$i=0;
		$shipping =0;
		 $sqlCart="select * from tempcart where session_id='".$sessid."'";
	  $resCart=mysql_query($sqlCart);
	  while($rowCart=mysql_fetch_array($resCart))
	  {
	  $i=1;
	  $itemId=$rowCart['itemid'];
$sqlSelItem="SELECT * FROM tbl_items WHERE item_id='$itemId'";
$rstSelItem=mysql_query($sqlSelItem);
$rowSelItem=mysql_fetch_array($rstSelItem);
$proId=$rowSelItem['product_id'];	
$productOwner=$rowSelItem['seller_id'];
$productDesc=$rowSelItem['product_description'];
$productCategory=$rowSelItem['category_id'];
$productPrice=$rowSelItem['price'];
$bargainAmount=$rowSelItem['price'];

$sqlSelProd="SELECT * FROM tbl_product p left join tbl_handling_time h on h.handling_time_id=p.shipping_id left join tbl_shipping_service s on p.courior_id=s.shipping_id  WHERE product_id='$proId'";
$rstSelProd=mysql_query($sqlSelProd);
$rowSelProd=mysql_fetch_array($rstSelProd);
$productOOwner=$rowSelProd['posted_by'];

$productName=$rowSelProd['product_name'];	
$postedDate=$rowSelProd['posted_date'];
$bargainDate = $rowSelProd['bargain_duration'];
$sellingType=$rowSelProd['selling_type'];
//$shipping = number_format($rowSelProd['shipping'],2);
//$shipping =0;
$shippCost=$rowSelProd['shipping'];

if($rowCart['isWhole']=='1')
{
	$sqlSelProd="SELECT * FROM tbl_wholeseller_product p WHERE product_id='$itemId'";
	$rstSelProd=mysql_query($sqlSelProd);
	$rowSelProd=mysql_fetch_array($rstSelProd);
}


	 if($sellingType=='both')
	 {
	 	$tempid=$rowCart['tempid'];
		$shippingAvailability="Free";
		
		if((int)$rowCart['is_online']==1)
		{
			if(((int)$rowSelProd['shipping'])>=0)
			{
				$shipping=$rowSelProd['shipping']+$shipping;
			}
			$online='checked=true';
			$offline="";			
		}
		else
		{
			//$shipping=$shipping;
			$offline='checked=true';
			$online="";
			$shippCost="";
		}	
		
		$pickupAvailability="<input type='radio' onclick='return set_online(0,$tempid);' $offline />Local<input type='radio' onclick='return set_online(1,$tempid);' $online />Online ";
			
	 }
	else if($sellingType=='online')
	 {
		$shippingAvailability="Free";
		$pickupAvailability="Not available";
		if(((int)$rowSelProd['shipping'])>=0)
		{
			$shipping=$rowSelProd['shipping']+$shipping;
		}
	 }
    else if($sellingType=='local')
	 {
		$shippingAvailability="Not available";
		$pickupAvailability="Free";
		//$shipping =0;
		$shippCost="";
		
		$sqlPost1="update tempcart set is_online='0',verify_code='".rand(1000000000,9999999999)."' where tempid='".$rowCart['tempid']."' ";
		$rstPost1=mysql_query($sqlPost1) or die(mysql_error());	
		//$shipping=$shipping;
	 }
	 $total=($rowSelProd['product_price']+number_format((number_format($rowCart['sales_tax'],2)*($rowSelProd['product_price'])/100),2))*(int)$rowCart['qty']+$total;
	 
	  ?>
        <tr>
          <td width="18%" valign="top">Item added on<br />
              <?php echo date("M d,Y",strtotime($rowSelItem['created_date']));?> </td>
          <td width="35%" valign="top"><?php echo $rowCart['itemname'];?><br />
            Condition:<?php echo $rowSelProd['pro_condition'];?><br />
            In Stock
			<br/><br/>
			Courior Type : <?php echo $rowSelProd['shipping_name'];?>
			<br/><br/>
			Shipping Time : <?php echo $rowSelProd['handling_time_name'];?>
			<br/><br/>
			Return Policy : <?php echo $rowSelProd['return_id'];?>
			
		  </td>
          <td valign="top"><?php echo $shippCost;?></td>
          <td valign="top" nowrap="nowrap"><?php echo $pickupAvailability;?></td>
          <td valign="top"><?php echo  number_format($rowCart['sales_tax'],2);?>%</td>
          <td valign="top">$<?php echo number_format($rowSelProd['product_price'],2);?></td>
          <td valign="top">
            <input name="qty<?php echo $rowCart['tempid'];?>" id="qty<?php echo $rowCart['tempid'];?>" type="text" size="2" value="<?php echo $rowCart['qty'];?>"/>          </td>
          <td valign="top"><a href="javascript:" onclick="return updateQty('<?php echo $rowCart['tempid'];?>');">Update</a><br />
          <a href="delete.php?id=<?php echo $rowCart['tempid'];?>">Delete</a></td>
        </tr>
       
        <?php }?>
		 <?php if($i==1)
		  {
		  ?>
		 <tr>
		   <td valign="top">&nbsp;</td>
		   <td valign="top">&nbsp;</td>
		   <td colspan="2" valign="top">&nbsp;</td>
		   <td colspan="4" valign="top"><strong>Sub Total: <?php echo number_format($total,2);?></strong></td>
        </tr>
		<tr>
		   <td valign="top">&nbsp;</td>
		   <td valign="top">&nbsp;</td>
		   <td colspan="2" valign="top">&nbsp;</td>
		   <td colspan="4" valign="top"><strong>Total Shipping: <?php echo number_format($shipping,2);?></strong></td>
        </tr>
		<?php $_SESSION['shipping'] = $shipping; ?>
		 <tr>
          <td valign="top">&nbsp;</td>
          <td valign="top">&nbsp;</td>
          <td colspan="2" align="right" valign="top"><a href="index.php">Continue Shopping </a></td>
          <td colspan="4" valign="top"><?php if($_SESSION['user_id_sess']) {?>
            <!--<a href="paypal.php">Make Payment</a>-->
			<a href="amazon.php"><img border="0" src="images/AmazonFPS.gif" alt="Amazon" width="134" height="35" />
            <?php } else { echo "Please login to proceed for checkout"; }?></td>
         </tr>
		 
		 <tr>
		   <td valign="top">&nbsp;</td>
		   <td valign="top">&nbsp;</td>
		   <td valign="top">&nbsp;</td>
		   <td colspan="5" align="right" valign="top">&nbsp;</td>
        </tr>
		<?php } else {?>
		 <tr>
		   <td colspan="8" align="center" valign="top"><strong>Your Cart is empty</strong></td>
	    </tr>
		<?php }?>
    </table>    </td>
  </tr>
</table>		 
